"""
请求对象的定制
解决反爬的第一种手段 UA
get 请求
urllib.parse.quote() 将字符串形式中文转化为 unicode 格式
urllib.parse.urlencode() 将字典形式中文转化为 unicode 格式,并实现自动拼接
"""

from urllib import request
import urllib.parse

url = "https://www.baidu.com"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"
}

# 请求对象的定制
req = request.Request(url=url, headers=headers)
response = request.urlopen(req)

content = response.read().decode("utf-8")
print(content)

param = {
    "wd": "许嵩",
    "sex": "男"
}

print(urllib.parse.urlencode(param))
